package com.yc.bdw.Utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by shuang on 2015/11/10.
 */
public class InputManager {

    private Context context;
    private  View view;
    private InputMethodManager inputMethodManager;

    public InputManager(){}

    public InputManager(Context context, View view) {
        this.context = context;
        this.view = view;
        inputMethodManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
    }

    public void hideSoftInput() {
        if (inputMethodManager != null) {
            View v = ((Activity)context).getCurrentFocus();
            if (v == null) {
                return;
            }
            inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            view.clearFocus();
        }
    }
}
